using UnityEngine;

public class TrainerDialogLayer : MonoBehaviour
{
	public delegate void OnDialogComplete(bool complete);

	protected OnDialogComplete onDialogComplete;

	public UILabel textLabel;

	public UILabel okLabel;

	public UILabel titleLabel;

	public GameObject dialogGameObject;

	public TweenScale display;

	public UISprite background;

	protected float backgroundAlpha;

	public static TrainerDialogLayer instance { get; protected set; }

	private void Awake()
	{
		backgroundAlpha = background.alpha;
		instance = this;
	}

	private void OnDestroy()
	{
		instance = null;
	}

	public void ShowOk(string text, string ok, OnDialogComplete onCompleteDialog)
	{
		ShowOk(string.Empty, text, ok, onCompleteDialog, backgroundAlpha);
	}

	public void ShowOk(string title, string text, string ok, OnDialogComplete onCompleteDialog)
	{
		ShowOk(title, text, ok, onCompleteDialog, backgroundAlpha);
	}

	public void ShowOk(string title, string text, string ok, OnDialogComplete onCompleteDialog, float bgAlpha)
	{
		onDialogComplete = onCompleteDialog;
		textLabel.text = text;
		UITools.ChangeText(titleLabel, title);
		background.alpha = 0.01f;
		TweenAlpha.Begin(background.cachedGameObject, 0.5f, bgAlpha);
		okLabel.text = ok;
		NavigationManager.instance.PushModal(dialogGameObject);
		display.ResetToBeginning();
		display.Play();
	}

	public void OnOk()
	{
		OnDialogComplete onDialogComplete = this.onDialogComplete;
		this.onDialogComplete = null;
		if (onDialogComplete != null)
		{
			onDialogComplete(true);
		}
		else
		{
			NavigationManager.instance.Pop(true);
		}
	}
}
